> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/mlfoundations/open_clip/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

> Install OpenCLIP for inference, training, or development

# Installation

OpenCLIP can be installed in multiple ways depending on your use case. This guide covers installation for inference, training, and development.

## Basic Installation

For inference and basic usage, install OpenCLIP via pip:

```bash theme={null}
pip install open_clip_torch
```

This installs the core package with dependencies for loading models and running inference.

<Note>
  The package name is `open_clip_torch` on PyPI, but you import it as `open_clip` in Python.
</Note>

## Optional Dependencies

Some models require additional packages depending on their architecture:

### Image Encoders (timm)

Many modern models use timm-based image encoders (ConvNext, SigLIP, EVA, etc.). Install the latest timm for full model support:

```bash theme={null}
pip install timm
```

<Warning>
  If you see "Unknown model" errors for the image encoder, upgrade timm to the latest version:

  ```bash theme={null}
  pip install --upgrade timm
  ```
</Warning>

### Tokenizers (transformers)

Models that use Hugging Face transformers tokenizers require the transformers library:

```bash theme={null}
pip install transformers
```

### Complete Installation

To install OpenCLIP with all optional dependencies:

```bash theme={null}
pip install open_clip_torch timm transformers
```

## Training Installation

For training CLIP models, install with training dependencies:

```bash theme={null}
pip install 'open_clip_torch[training]'
```

This includes additional packages for:

* Distributed training
* Data loading and augmentation
* Logging and monitoring
* WebDataset support

<Note>
  Training requires PyTorch to be installed separately. Follow the [PyTorch installation guide](https://pytorch.org/get-started/locally/) for your specific system configuration.
</Note>

## Development Installation

For contributors or those who want to modify the code:

<Steps>
  <Step title="Create a virtual environment">
    First, create and activate a virtual environment:

    ```bash theme={null}
    python3 -m venv .env
    source .env/bin/activate
    pip install -U pip
    ```
  </Step>

  <Step title="Clone the repository">
    Clone the OpenCLIP repository:

    ```bash theme={null}
    git clone https://github.com/mlfoundations/open_clip.git
    cd open_clip
    ```
  </Step>

  <Step title="Install in development mode">
    Install the package in editable mode:

    ```bash theme={null}
    make install
    ```

    Or install training dependencies:

    ```bash theme={null}
    make install-training
    ```
  </Step>

  <Step title="Install PyTorch">
    Install PyTorch according to your system:

    ```bash theme={null}
    # Visit https://pytorch.org/get-started/locally/
    # Example for CUDA 11.8:
    pip install torch torchvision --index-url https://download.pytorch.org/whl/cu118
    ```
  </Step>
</Steps>

## Testing Installation

To verify your installation and run tests:

### Install test dependencies

```bash theme={null}
make install-test
```

### Run all tests

```bash theme={null}
make test
```

### Run specific tests

```bash theme={null}
# Run training tests only
python -m pytest -x -s -v tests -k "training"

# Run inference tests
python -m pytest -x -s -v tests -k "inference"
```

## Verification

Verify your installation by loading a pretrained model:

```python theme={null}
import open_clip
import torch

# List available pretrained models
print(open_clip.list_pretrained()[:5])  # Show first 5

# Load a model
model, _, preprocess = open_clip.create_model_and_transforms(
    'ViT-B-32',
    pretrained='laion2b_s34b_b79k'
)

print("Installation successful!")
```

If this runs without errors, your installation is complete.

## Platform-Specific Notes

### Linux

OpenCLIP works out of the box on most Linux distributions. For CUDA support, ensure you have:

* NVIDIA drivers installed
* CUDA toolkit matching your PyTorch version

### macOS

OpenCLIP works on macOS with CPU or MPS (Apple Silicon) acceleration:

```python theme={null}
import torch
import open_clip

# Use MPS on Apple Silicon
device = "mps" if torch.backends.mps.is_available() else "cpu"
model, _, preprocess = open_clip.create_model_and_transforms(
    'ViT-B-32',
    pretrained='openai',
    device=device
)
```

### Windows

For Windows, we recommend using WSL2 (Windows Subsystem for Linux) for the best experience, especially for training. Native Windows installation works but may have some limitations.

## Troubleshooting

<Accordion title="ImportError: cannot import name 'open_clip'">
  Make sure you're importing the correct name:

  ```python theme={null}
  import open_clip  # Correct
  # NOT: import open_clip_torch
  ```
</Accordion>

<Accordion title="CUDA out of memory errors">
  Reduce batch size or use gradient accumulation:

  ```python theme={null}
  # Use mixed precision to save memory
  model, _, preprocess = open_clip.create_model_and_transforms(
      'ViT-B-32',
      pretrained='openai',
      precision='fp16'  # or 'bf16'
  )
  ```
</Accordion>

<Accordion title="'Unknown model' error">
  This usually means a timm model is not found. Upgrade timm:

  ```bash theme={null}
  pip install --upgrade timm
  ```
</Accordion>

<Accordion title="Slow model loading">
  Models are cached after first download. The cache location can be set:

  ```python theme={null}
  model, _, preprocess = open_clip.create_model_and_transforms(
      'ViT-B-32',
      pretrained='openai',
      cache_dir='/path/to/cache'
  )
  ```
</Accordion>

## Next Steps

Now that OpenCLIP is installed, proceed to the quickstart guide to run your first example:

* [Quickstart Guide](/quickstart) - Run zero-shot classification
* \[Model Zoo(/usage/pretrained-models) - Browse available models
* \[Training Guide(/training/overview) - Train your own CLIP models
